package com.atguigu.headline.util;

import java.util.Arrays;
import java.util.List;

public class SensitiveWordFilter {
    private static ACAutomaton acAutomaton;

    static {
        // 初始化敏感词库,只能用英文
        List<String> sensitiveWords = Arrays.asList("sb", "114514", "yyc", "zxx","tmd",",",".","=","-","+","/","*","?",">","<",":","{","}","`","~","!","@","#","$","%","^","&","*","[","]","|");
        acAutomaton = new ACAutomaton();
        acAutomaton.buildTrie(sensitiveWords);
        acAutomaton.buildFailPointers();
    }

    public static boolean containsSensitiveWord(String text) {
        List<String> foundWords = acAutomaton.search(text);
        return !foundWords.isEmpty();
    }
}